<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class EntryExitRecord extends Model
{
    protected $table = 'entry_exit_record';

    protected $fillable = [
    	'order_systemnumber',
    	'vehicle_number',
    	'tare',
    	'driver_name',
    	'readic_datetime',
    	'net_weight',
    	'io_status',
    	'capvn_path',
    	'cap_a_path',
    	'cap_b_path',
    	'cap_c_path',
    	'is_finished'
    ];

    protected $appends = [
    	'io_status_desc',
    	'is_finished_desc'
    ];

    const IO_STATUS_ZERO = 0;

    const IO_STATUS_ONE = 1;

    public static $IO_STATUS = [
    	self::IO_STATUS_ZERO => '入厂',
    	self::IO_STATUS_ONE => '出厂'
    ];

    const IS_FINISHED_YES = 'Y';

    const IS_FINISHED_NO = 'N';

    public static $IS_FINISHED = [
        self::IS_FINISHED_YES => '是',
        self::IS_FINISHED_NO => '否'
    ];

    public function getIoStatusDescAttribute(){
    	if(array_key_exists('io_status', $this->attributes)){
    		return $this->attributes['io_status_desc'] = self::$IO_STATUS[$this->attributes['io_status']];
    	}
    }

    public function getIsFinishedDescAttribute(){
        if(array_key_exists('is_finished', $this->attributes) && $this->attributes['is_finished'] != null){
            return $this->attributes['is_finished_desc'] = self::$IS_FINISHED[$this->attributes['is_finished']];
        }
    }
}
